package internal

import (
	"github.com/GoAdminGroup/go-admin/engine"
	"github.com/GoAdminGroup/go-admin/examples/datamodel"
	"github.com/GoAdminGroup/go-admin/modules/config"
	"github.com/GoAdminGroup/go-admin/modules/language"
	"github.com/GoAdminGroup/go-admin/template"
	"github.com/GoAdminGroup/go-admin/template/chartjs"
	"github.com/GoAdminGroup/themes/adminlte"
	"github.com/beherochuling/beesoft_api/app/helper/helper"
	"github.com/gogf/gf/v2/frame/g"

	"github.com/beherochuling/beesoft_api/app/admin"
)

func initGoAdmin() {
	initGoAdminAdapter()

	eng := engine.Default()
	adminUploadDir := helper.File.GetStorageDir("admin/uploads")

	group := "media"
	cfg := config.Config{
		Env:                config.EnvProd,
		InfoLogOff:         true,
		AccessAssetsLogOff: true,
		Databases: config.DatabaseList{
			"default": {
				Driver: config.DriverMysql,
				Host:   g.DB(group).GetConfig().Host,
				Port:   g.DB(group).GetConfig().Port,
				User:   g.DB(group).GetConfig().User,
				Pwd:    g.DB(group).GetConfig().Pass,
				Name:   g.DB(group).GetConfig().Name,
				// MaxIdleCon: 50,
				// MaxOpenCon: 150,
			},
		},
		UrlPrefix: "admin",
		Store: config.Store{
			Path:   adminUploadDir,
			Prefix: "uploads",
		},
		Language:    language.CN,
		IndexUrl:    "/",
		Debug:       false,
		ColorScheme: adminlte.ColorschemeSkinBlack,

		// RedisHost:     g.Config().GetString("redis.host"),
		// RedisPort:     g.Config().GetInt("redis.port"),
		// RedisDB:       g.Config().GetInt("redis.db"),
		// RedisPassword: g.Config().GetString("redis.password"),
	}

	s := g.Server()
	s.AddStaticPath("/uploads", adminUploadDir)
	if err := eng.AddConfig(&cfg).
		AddGenerators(datamodel.Generators).
		AddDisplayFilterXssJsFilter().
		AddGenerator("user", datamodel.GetUserTable).
		Use(s); err != nil {
		panic(err)
	}

	template.AddComp(chartjs.NewChart())

	admin.Init(eng)
	// easyLogin.Init(s, eng) // 注入OA登录
}
